//获取登录按钮
let login = document.querySelector('section .member>div')
login.onclick = function () {//绑定事件
    document.querySelector('section.login').style.visibility = 'visible'//处理函数
}
let close = document.querySelector('section.login .item .icon-close')
close.onclick = function () {
    document.querySelector('section.login').style.visibility = 'hidden'//处理函数
    document.querySelector('section.login p.msg1').style.visibility = 'hidden'
    document.querySelector('section.login p.msg2').style.visibility = 'hidden'
}
//获取蓝色框注册鼠标按下事件=》网页移动事件=》鼠标松开事件
let blueMenu = document.querySelector('section.login .menu')
blueMenu.onmousedown = function (evt) {
    let oldE = evt || window.event
    document.onmousemove = function (evt) {
        let e = evt || window.event
        let left = e.pageX - oldE.offsetX
        let top = e.pageY - oldE.offsetY
        let item = document.querySelector('section.login .item')
        let maxLeft = document.documentElement.clientWidth - item.offsetWidth
        let maxTop = document.documentElement.clientHeight - item.offsetHeight
        if (left < 0) left = 0
        if (top < 0) top = 0
        if (left >= maxLeft) left = maxLeft
        if (top >= maxTop) top = maxTop
        item.style.position = 'absolute'
        item.style.left = left + 'px'
        item.style.top = top + 'px'
    }
    blueMenu.onmouseup = function () {
        document.onmousemove = null
    }
}
let mobileBtn = document.querySelector('section.login .mobile')
let passwordBtn = document.querySelector('section.login .password')
mobileBtn.onblur = function () {
    if (/^1\d{10}$/.test(mobileBtn.value)) {
        mobileBtn.nextElementSibling.style.visibility = 'hidden'
        mobileBtn.nextElementSibling.innerText = ''
    } else {
        mobileBtn.nextElementSibling.style.visibility = 'visible'
        mobileBtn.nextElementSibling.innerText = '请输入正确手机号码'
    }
}
mobileBtn.onfocus = function () {
    mobileBtn.nextElementSibling.style.visibility = 'hidden'
}
passwordBtn.onblur = function () {
    if (/^\d{4}$/.test(passwordBtn.value)) {
        passwordBtn.nextElementSibling.style.visibility = 'hidden'
        mobileBtn.nextElementSibling.innerText = ''
    } else {
        passwordBtn.nextElementSibling.style.visibility = 'visible'
        passwordBtn.nextElementSibling.innerText = '验证码不正确'
    }
}
passwordBtn.onfocus = function () {
    passwordBtn.nextElementSibling.style.visibility = 'hidden'
}
document.querySelector('section.login .submit').onclick = function () {
    var success = 0

    if (/^1\d{10}$/.test(mobileBtn.value)) {
        success++
        mobileBtn.nextElementSibling.style.visibility = 'hidden'
        mobileBtn.nextElementSibling.innerText = ''
    } else {
        mobileBtn.nextElementSibling.style.visibility = 'visible'
        mobileBtn.nextElementSibling.innerText = '请输入正确手机号码'
    }
    if (/^\d{4}$/.test(passwordBtn.value)) {
        success++
        passwordBtn.nextElementSibling.style.visibility = 'hidden'
        mobileBtn.nextElementSibling.innerText = ''
    } else {
        passwordBtn.nextElementSibling.style.visibility = 'visible'
        passwordBtn.nextElementSibling.innerText = '验证码不正确'
    }
    if (success == 2) {
        alert('成功')
    }
}

let captchaBtn = document.querySelector('section.login .captcha')
let num = 5
captchaBtn.onclick = function () {
    let captchaObj = document.querySelector('section.captcha')
    captchaObj.style.visibility = 'visible'
    let iconClose = document.querySelector('section.captcha .icon-close')
    iconClose.onclick = function () {
        captchaObj.style.visibility = 'hidden'
    }
    let dragBtn = document.querySelector('section.captcha .btn')
    dragBtn.onmousedown = function (evt) {
        let olde = evt || window.event
        let offLeft = olde.pageX
        let dragObj = document.querySelector('section.captcha .drag')
        let imgCheck = document.querySelector('section.captcha .check>img:nth-of-type(2)')
        document.onmousemove = function (evt) {
            let e = evt || window.event
            let left = e.pageX - offLeft
            let maxLeft = dragObj.offsetWidth - dragBtn.offsetWidth
            if (left < 0) left = 0
            if (left >= maxLeft) left = maxLeft
            dragBtn.style.left = left + 'px'
            imgCheck.style.left = left + 'px'
        }
        document.onmouseup = function () {
            document.onmousemove = null
            let value = parseInt(dragBtn.style.left)
            if (value >= 260 && value <= 265) {
                captchaObj.style.visibility = 'hidden'
                captchaBtn.innerText = `${num}秒后重发`
                captchaBtn.disabled = true

                t = setInterval(function () {
                    if (num <= 1) {
                        clearInterval(t)
                        captchaBtn.innerText = '重新发送'
                        num = 5
                        captchaBtn.disabled = false
                        return
                    }
                    num--
                    captchaBtn.innerText = `${num}秒后重发`

                }, 1000)
            }
            dragBtn.style.left = 0
            imgCheck.style.left = 0
        }
    }
    return
}















